<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/28
 * Time: 15:01
 */

namespace app\web\controller;

use app\common\controller\WebBase;
use think\Session;
use app\common\model\Article as ArticleModel;
use app\common\model\Blog as BlogModel;

class Index extends WebBase{
    private $_article_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->_article_model = new  ArticleModel() ;
    }

    /*
     * 前台首页
     * 展示欢迎界面 显示所有文章列表
     * */
    public function index($id=1){
        $ob = new BlogModel();
        $re = $ob->showOneBlog($id);
        $webType = $re[0]['web_type'];
        if($id == 1) {
            $this->assign('webType',$webType);
            $this->assign('results', $re);
            $this->assign('title', array(
                'title' => '首页'
            ));
        }else{
            $this->redirect('Index/detail',['id'=>$id]);
        }
        return $this->fetch();

    }

    /*
     *
     * */
    public function detail($id = ''){
        $ob = new BlogModel();
        $re = $ob->showOneBlog($id);
        $webType = $re[0]['web_type'];
        // 从数据库获取数据
        if(!$re | !$id){
            $this->error('文章已经被删除或者不存在','Index/index');
        }elseif ($id == 1){
            $this->redirect('Index/index');
        }else{
            $this->assign('result', $re[0]);
            $this->assign('results', $re);
            $this->assign('webType',$webType);
            $this->assign('title',array(
                'title'=>'文案'
            ));
//            var_dump($resutl);
//            $this->view->engine->layout('base');
            return $this->fetch();
        }

    }



    /*
     *
     * */
    public function base2($id=0){
        // 从数据库获取数据
        if(empty($id)){
            $this->error('文章已经被删除或者不存在','Index/index');
        }else{
            $re =  $this->_article_model->showOneArticle($id);
            $this->assign('title',array(
                'title'=>'文案'
            ));
            $this->assign('results',$re);
//            var_dump($resutl);
            return $this->fetch();
        }

    }






















}